package com.heima.common.tess4j;

import lombok.Data;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.awt.image.BufferedImage;

@Data
public class Tess4jClient {
    private String dataPath;
    private  String language;

    private  String  doOCR(BufferedImage image) throws TesseractException {
        //穿件Tesseract对象
        Tesseract tesseract = new Tesseract();
        //设置上字体库路径
        tesseract.setDatapath(dataPath);
        //设置语言
        tesseract.setLanguage(language);
        //执行识别功能
        String result = tesseract.doOCR(image);
        //优化结果-->将换行替换为-,并返回结果
        return result = result.replaceAll("\\n|\\r", "-");
    }
}
